package cn.tannn.surenessdemo.sureness.provider;

import cn.tannn.surenessdemo.redis.service.RedisService;
import cn.tannn.surenessdemo.user.service.AccountService;
import cn.tannn.surenessdemo.user.service.TreePathRoleMatcherService;
import com.usthe.sureness.provider.SurenessAccount;
import com.usthe.sureness.provider.SurenessAccountProvider;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 用户相关的方法，注入到 sureness中 使用
 *
 * @author tomsun28
 * @date 22:44 2020-03-02
 */
@Component
public class DatabaseAccountProvider implements SurenessAccountProvider {

    final AccountService accountService;

    /**
     * reids
     */
    final RedisService redisTemplate;


    final TreePathRoleMatcherService treePathRoleMatcherService;


    public DatabaseAccountProvider(AccountService accountService,
                                   RedisService redisTemplate,
                                   TreePathRoleMatcherService treePathRoleMatcherService) {
        this.accountService = accountService;
        this.redisTemplate = redisTemplate;
        this.treePathRoleMatcherService = treePathRoleMatcherService;
    }

    @Override
    public SurenessAccount loadAccount(String username) {
        return accountService.loadAccountStatus(username);
    }

    /**
     * 获取用户权限
     *
     * @param username 用户唯一编码
     * @return List
     */
    public List<String> loadAccountRoles(String username) {
        return accountService.loadAccountRoles(username);
    }

    /**
     * 加载redis工具类
     *
     * @return RedisTemplate
     */
    public RedisService redisTemplate() {
        return redisTemplate;
    }

    /**
     * 得到 treePathRoleMatcherService
     * @return TreePathRoleMatcherService
     */
    public TreePathRoleMatcherService treePathRoleMatcherServiceTemplate() {
        return treePathRoleMatcherService;
    }


}
